<template>
	<view>
		<form>
			<view class="cu-form-group">
				<view class="title">旧密码</view>
				<input v-model="form.name" placeholder="请输入旧密码" name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">新密码</view>
				<input placeholder="请输入新密码" name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">确认密码</view>
				<input placeholder="请确认新密码" name="input" v-model="form.originalPrice" type="number"></input>
			</view>
		</form>
		<view class="operation-btn-wrap">
			<button class="cu-btn round bg-green margin-tb-sm lg operation-btn">确 定</button>
			<button class="cu-btn round bg-white margin-tb-sm lg operation-btn">取 消</button>
		</view>
	</view>
</template>

<script>
	import goodsApi from '@/api/goods.js';
	import config from '@/config.js';
	export default {
		data() {
			return {
				form: {
				  name: '',
				  banner: [],
				  details: [],
				  originalPrice: '',
				  discountPrice: '',
				  repertory: '',
				  unit: '',
				  classify: {
					id: '',
					name: '',
					icon: ''
				  },
				  merchantId: ''
				},
				index: -1,
				bannerImgList: [],
				detailImgList: [],
				picker: ['喵喵喵', '汪汪汪', '哼唧哼唧']
			};
		},
		created() {
			goodsApi.getClassify().then(res => {
				// console.log(res.data.data);
			});
		},
		methods: {
			pickerChange(e) {
				this.index = e.detail.value
			},
			chooseImage(target) {
				const self = this;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						/* if (this.bannerImgList.length != 0) {
							this.bannerImgList = this.bannerImgList.concat(res.tempFilePaths)
						} else {
							this.bannerImgList = res.tempFilePaths
						} */
						console.log(`${target}ImgList`);
						const tempFile = res.tempFilePaths[0];
						self[`${target}ImgList`].push(tempFile);
						//self.requestUpload(tempFile, target);
					}
				});
			},
			viewImage(e) {
				uni.previewImage({
					urls: this.bannerImgList,
					current: e.currentTarget.dataset.url
				});
			},
			delImg(e) {
				this.bannerImgList.splice(e.currentTarget.dataset.index, 1)
			},
			requestUpload(filePath, target) {
				const self = this;
				uni.uploadFile({
					url: `${config.network.baseUrl}/system/upload`,
					filePath: filePath,
					name: 'file',
					success: res => {
						const data = JSON.parse(res.data);
						self.form[target].push(data.data.filename);
					},
					fail(err) {
						console.log(err);
					},
					complete(res) {
						if (res.statusCode !== 200) {
							uni.showToast({
								title: '系统异常：' + res.statusCode,
								icon: 'none'
							});
						}
					}
				});
			},
		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
</style>
